package com.tomato.thread.pool;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import static java.text.MessageFormat.format;

/**
 * 该线程池核心线程数为 1 ，最大线程数也为 1
 * 使用 LinkedBlockingQueue存储队列
 * 在任务多且任务较为耗时的情况下，会产生OOM情况
 */
public class SingleThreadPool {
    public static void main(String[] args) {
        ExecutorService executorService = Executors.newSingleThreadExecutor();
        for (int i = 0; i <= 100; i++) {
            executorService.execute(() -> {
                System.out.println(format("{0}执行任务", Thread.currentThread().getName()));
            });
        }
    }
}
